import axios from 'axios';
import * as https from 'https';

const url = 'https://api.powerbi.com/beta/e96fa72b-c8d6-4957-96bd-c7f8dc30cc88/datasets/31fb02b8-3e95-4bec-b9b2-5af9c0d67aa0/rows?experience=power-bi&key=28Ri5RxnC5wvZFax5umuUDI2FZi6LxZ6q1bZPLqtfNfSXkLIuxqvge6bkETamwjdYIo%2F0EP8sgoAVzi55wI2Dw%3D%3D';

export async function sendMonitoringData(data: any): Promise<void> {
    try {
        console.log('sending pbi data:', data);
        // 忽略HTTPS证书验证（注意：这在生产环境中不安全）
        const agent = new https.Agent({ rejectUnauthorized: false });
        const response = await axios.post(url, data, { httpsAgent: agent });
        console.log('status code：', response.status);
        console.log('respose data：', response.data);
    } catch (error: any) {
        console.error('Error sending monitoring data:', error.message);
        if (error.response) {
            console.error('Response status:', error.response.status);
            console.error('Response data:', error.response.data);
        } else if (error.request) {
            console.error('No response received:', error.request);
        } else {
            console.error('Error setting up the request:', error.message);
        }    }
}